﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenerateAdminPage.Classes.Views
{
    #region USING
    using GenerateAdminPage.Classes.DBStructure;
    #endregion

    /// <summary>
    /// Man hinh hien thi de cap nhat chi tiet cho bang co quan he one-many 
    /// </summary>
    public class ViewOneToMany : AbstractViews
    {
        public override string GenerateFields()
        {
            StringBuilder Result = new StringBuilder();

            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel1;");
            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel2;");
            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel3;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.LabelX lblCapNhat" + TblMany.Name + ";");

            for (int i = 0; i < TblMany.Attributes.Count; i++)
            {
                if (TblMany.Attributes[i].IsPrimaryKey ||
                    (TblMany.Attributes[i].IsForeignKey && TblMany.Attributes[i].ReferTo == TblOne.Name))
                {
                    continue;
                }

                Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.LabelX lbl" + TblMany.Attributes[i].Name + ";");

                if (TblMany.Attributes[i].IsForeignKey)
                {
                    Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.TextBoxX txt" + TblMany.Attributes[i].ReferTo + ";");
                    Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnChon" + TblMany.Attributes[i].ReferTo + ";");
                }
                else
                {
                    if (TblMany.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.Editors.DateTimeAdv.DateTimeInput dt" + TblMany.Attributes[i].Name + ";");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.ComboBoxEx cbx" + TblMany.Attributes[i].Name + ";");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.PictureBox ptb" + TblMany.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnChon" + TblMany.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnXoa" + TblMany.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.OpenFileDialog openFileDialog1;");
                    }
                    else
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.TextBoxX txt" + TblMany.Attributes[i].Name + ";");
                    }
                }
            }

            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnCapNhat;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnThoat;");

            return Result.ToString();
        }

        public override string GenerateInitializeComponent()
        {
            StringBuilder Result = new StringBuilder();
            var numAttr = 0;

            Result.AppendLine(TAB2 + "private void InitializeComponent()");
            Result.AppendLine(TAB2 + "{");
            Result.AppendLine(TAB3 + "System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmCapNhat" + TblMany.Name + "));");
            Result.AppendLine(TAB3 + "this.panel1 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.panel2 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.panel3 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.btnCapNhat = new DevComponents.DotNetBar.ButtonX();");
            Result.AppendLine(TAB3 + "this.btnThoat = new DevComponents.DotNetBar.ButtonX();");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + " = new DevComponents.DotNetBar.LabelX();");

            var count = 0;
            for (int i = 0; i < TblMany.Attributes.Count; i++)
            {
                if (TblMany.Attributes[i].IsPrimaryKey ||
                    (TblMany.Attributes[i].IsForeignKey && TblMany.Attributes[i].ReferTo == TblOne.Name))
                {
                    continue;
                }

                numAttr++;
                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + " = new DevComponents.DotNetBar.LabelX();");

                if (TblMany.Attributes[i].IsForeignKey)
                {
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + " = new DevComponents.DotNetBar.Controls.TextBoxX();");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + " = new System.Windows.Forms.Button();");
                }
                else
                {
                    if (TblMany.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + " = new DevComponents.Editors.DateTimeAdv.DateTimeInput();");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + " = new DevComponents.DotNetBar.Controls.ComboBoxEx();");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + " = new System.Windows.Forms.PictureBox();");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + " = new System.Windows.Forms.Button();");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + " = new System.Windows.Forms.Button();");

                        if (count == 0)
                        {
                            Result.AppendLine(TAB3 + "this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();");
                            count++;
                        }
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + " = new DevComponents.DotNetBar.Controls.TextBoxX();");
                    }
                }
            }

            Result.AppendLine(TAB3 + "this.panel1.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.panel2.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.panel3.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.SuspendLayout();" + END);

            Result.AppendLine(TAB3 + "this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));");
            Result.AppendLine(TAB3 + "this.panel1.Controls.Add(this.panel3);");
            Result.AppendLine(TAB3 + "this.panel1.Controls.Add(this.panel2);");
            Result.AppendLine(TAB3 + "this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;");
            Result.AppendLine(TAB3 + "this.panel1.Location = new System.Drawing.Point(0, 0);");
            Result.AppendLine(TAB3 + "this.panel1.Name = \"panel1\";");
            Result.AppendLine(TAB3 + "this.panel1.Size = new System.Drawing.Size(310, 178);");
            Result.AppendLine(TAB3 + "this.panel1.TabIndex = 2;" + END);

            Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.lblCapNhat" + TblMany.Name + ");");

            for (int i = 0; i < TblMany.Attributes.Count; i++)
            {
                if (TblMany.Attributes[i].IsPrimaryKey ||
                    (TblMany.Attributes[i].IsForeignKey && TblMany.Attributes[i].ReferTo == TblOne.Name))
                {
                    continue;
                }

                Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.lbl" + TblMany.Attributes[i].Name + ");");

                if (TblMany.Attributes[i].IsForeignKey)
                {
                    Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.txt" + TblMany.Attributes[i].ReferTo + ");");
                    Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnChon" + TblMany.Attributes[i].ReferTo + ");");
                }
                else
                {
                    if (TblMany.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.dt" + TblMany.Attributes[i].Name + ");");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.cbx" + TblMany.Attributes[i].Name + ");");
                    }
                    else if (TblMany.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.ptb" + TblMany.Attributes[i].Name + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnChon" + TblMany.Attributes[i].Name + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnXoa" + TblMany.Attributes[i].Name + ");");
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.txt" + TblMany.Attributes[i].Name + ");");
                    }
                }
            }

            Result.AppendLine(TAB3 + "this.panel2.Dock = System.Windows.Forms.DockStyle.Top;");
            Result.AppendLine(TAB3 + "this.panel2.Location = new System.Drawing.Point(0, 0);");
            Result.AppendLine(TAB3 + "this.panel2.Name = \"panel2\";");

            int panel2Size = 133;
            if (numAttr > 3)
            {
                panel2Size += OFFSET_Y * (TblMany.Attributes.Count - 3);
            }

            Result.AppendLine(TAB3 + "this.panel2.Size = new System.Drawing.Size(310, " + panel2Size + ");");
            Result.AppendLine(TAB3 + "this.panel2.TabIndex = 335;" + END);

            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnCapNhat);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnThoat);");
            Result.AppendLine(TAB3 + "this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;");
            Result.AppendLine(TAB3 + "this.panel3.Location = new System.Drawing.Point(0, 133);");
            Result.AppendLine(TAB3 + "this.panel3.Name = \"panel3\";");
            Result.AppendLine(TAB3 + "this.panel3.Size = new System.Drawing.Size(310, 45);");
            Result.AppendLine(TAB3 + "this.panel3.TabIndex = 336;" + END);

            Result.AppendLine(TAB3 + "this.btnCapNhat.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Image = ((System.Drawing.Image)(resources.GetObject(\"btnCapNhat.Image\")));");
            Result.AppendLine(TAB3 + "this.btnCapNhat.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Location = new System.Drawing.Point(117, 11);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Name = \"btnCapNhat\";");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Size = new System.Drawing.Size(91, 23);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.TabIndex = 43;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Text = \"Cập nhật\";");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Click += new System.EventHandler(this.btnCapNhat_Click);" + END);

            Result.AppendLine(TAB3 + "this.btnThoat.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnThoat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnThoat.Image = ((System.Drawing.Image)(resources.GetObject(\"btnThoat.Image\")));");
            Result.AppendLine(TAB3 + "this.btnThoat.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnThoat.Location = new System.Drawing.Point(226, 11);");
            Result.AppendLine(TAB3 + "this.btnThoat.Name = \"btnThoat\";");
            Result.AppendLine(TAB3 + "this.btnThoat.Size = new System.Drawing.Size(72, 23);");
            Result.AppendLine(TAB3 + "this.btnThoat.TabIndex = 40;");
            Result.AppendLine(TAB3 + "this.btnThoat.Text = \"Thoát\";");
            Result.AppendLine(TAB3 + "this.btnThoat.Click += new System.EventHandler(this.btnThoat_Click);" + END);

            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".AutoSize = true;");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".ForeColor = System.Drawing.Color.Crimson;");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".Location = new System.Drawing.Point(58, 15);");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".Name = \"lblCapNhat" + TblMany.Name + "\";");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".Size = new System.Drawing.Size(187, 19);");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".TabIndex = 1;");
            Result.AppendLine(TAB3 + "this.lblCapNhat" + TblMany.Name + ".Text = \"Cập nhật " + TblMany.Name + "\";" + END);

            int firstLabelY = 46;
            int firstTextboxY = 47;
            bool isFirst = false;
            count = 0;
            for (int i = 0; i < TblMany.Attributes.Count; i++)
            {
                if (TblMany.Attributes[i].IsPrimaryKey ||
                    (TblMany.Attributes[i].IsForeignKey && TblMany.Attributes[i].ReferTo == TblOne.Name))
                {
                    continue;
                }

                if (isFirst)
                {
                    firstLabelY += OFFSET_Y;
                    firstTextboxY += OFFSET_Y;
                }

                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + ".Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(10, " + firstLabelY.ToString() + ");");
                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + ".Name = \"labelX" + (i + 1) + "\";");
                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(68, 20);");
                Result.AppendLine(TAB3 + "this.lbl" + TblMany.Attributes[i].Name + ".Text = \"" + TblMany.Attributes[i].Name + "\";" + END);

                if (TblMany.Attributes[i].IsForeignKey)
                {
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + ".Border.Class = \"TextBoxBorder\";");
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + ".Location = new System.Drawing.Point(84, " + firstTextboxY.ToString() + ");");
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + ".Name = \"txt" + TblMany.Attributes[i].ReferTo + "\";");
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + ".ReadOnly = true;");
                    Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].ReferTo + ".Size = new System.Drawing.Size(180, 20);");

                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnChonThamChieu.Image\")));");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".Location = new System.Drawing.Point(" + (84 + 180 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".Name = \"btnChon" + TblMany.Attributes[i].ReferTo + "\";");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".Size = new System.Drawing.Size(28, 27);");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".UseVisualStyleBackColor = true;");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".Click += new System.EventHandler(this.btnChon" + TblMany.Attributes[i].ReferTo + "_Click);");
                    Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].ReferTo + ".TabIndex = " + i.ToString() + ";" + END);
                }
                else
                {
                    if (TblMany.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".BackgroundStyle.Class = \"DateTimeInputBackground\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".ButtonDropDown.Visible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".CustomFormat = \"dd/MM/yyyy\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".Format = DevComponents.Editors.eDateTimePickerFormat.Custom;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(84, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.AnnuallyMarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.BackgroundStyle.BackColor = System.Drawing.SystemColors.Window;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.ClearButtonVisible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColorGradientAngle = 90;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTopColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTopWidth = 1;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.MarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.MonthlyMarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColorGradientAngle = 90;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".MonthCalendar.TodayButtonVisible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".Name = \"dt" + TblMany.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(180, 20);");
                        Result.AppendLine(TAB3 + "this.dt" + TblMany.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                    else if (TblMany.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".DisplayMember = \"Text\";");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".FormattingEnabled = true;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".ItemHeight = 14;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(84, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".Name = \"cbx" + TblMany.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(114, 20);");
                        Result.AppendLine(TAB3 + "this.cbx" + TblMany.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                    else if (TblMany.Attributes[i].Type == DataType.IMAGE)
                    {
                        if (count == 0)
                        {
                            Result.AppendLine(TAB3 + "this.openFileDialog1.FileName = \"openFileDialog1\";");
                            count++;
                        }

                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".Anchor = System.Windows.Forms.AnchorStyles.Top;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".InitialImage = null;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(84, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".Name = \"ptb" + TblMany.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(148, 91);");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblMany.Attributes[i].Name + ".TabStop = false;");

                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnChonThamChieu.Image\")));");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(" + (84 + 148 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".Name = \"btnChon" + TblMany.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(28, 27);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".UseVisualStyleBackColor = true;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".Click += new System.EventHandler(this.btnChon" + TblMany.Attributes[i].Name + "_Click);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblMany.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);

                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnXoa.Image\")));");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(" + (84 + 148 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".Name = \"btnXoa" + TblMany.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(28, 27);");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".UseVisualStyleBackColor = true;");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblMany.Attributes[i].Name + ".Click += new System.EventHandler(this.btnXoa" + TblMany.Attributes[i].Name + "_Click);");
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".Border.Class = \"TextBoxBorder\";");
                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".Location = new System.Drawing.Point(84, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".Name = \"txt" + TblMany.Attributes[i].Name + "\";");

                        if (TblMany.Attributes[i].IsPrimaryKey && TblMany.Attributes[i].IsIdentify)
                        {
                            Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".ReadOnly = true;");
                        }

                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".Size = new System.Drawing.Size(180, 20);");
                        Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";");

                        if (TblMany.Attributes[i].Type == DataType.INT ||
                        TblMany.Attributes[i].Type == DataType.DOUBLE ||
                        TblMany.Attributes[i].Type == DataType.FLOAT ||
                        TblMany.Attributes[i].Type == DataType.LONG)
                        {
                            Result.AppendLine(TAB3 + "this.txt" + TblMany.Attributes[i].Name + ".KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt" + TblMany.Attributes[i].Name + "_KeyPress);" + END);
                        }
                    }
                }
                isFirst = true;
            }

            int ClientSize = 178;
            if (numAttr > 3)
            {
                ClientSize += OFFSET_Y * (TblMany.Attributes.Count - 3);
            }
            Result.AppendLine(TAB3 + "this.ClientSize = new System.Drawing.Size(310, " + ClientSize + ");");
            Result.AppendLine(TAB3 + "this.Controls.Add(this.panel1);");
            Result.AppendLine(TAB3 + "this.DoubleBuffered = true;");
            Result.AppendLine(TAB3 + "this.MaximizeBox = false;");
            Result.AppendLine(TAB3 + "this.MinimizeBox = false;");
            Result.AppendLine(TAB3 + "this.Name = \"FrmCapNhat" + TblMany.Name + "\";");
            Result.AppendLine(TAB3 + "this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;");
            Result.AppendLine(TAB3 + "this.Text = \"Cập nhật " + TblMany.Name + "\";");
            Result.AppendLine(TAB3 + "this.panel1.ResumeLayout(false);");
            Result.AppendLine(TAB3 + "this.panel3.ResumeLayout(false);");
            Result.AppendLine(TAB3 + "this.panel2.ResumeLayout(false);");
            Result.AppendLine(TAB3 + "this.panel2.PerformLayout();");
            Result.AppendLine(TAB3 + "this.ResumeLayout(false);");
            Result.AppendLine(TAB2 + "}");

            return Result.ToString();
        }
    }
}
